package Util;

import java.io.IOException; 
import java.io.Reader; 

import org.apache.ibatis.io.Resources; 
import org.apache.ibatis.session.SqlSessionFactory; 
import org.apache.ibatis.session.SqlSessionFactoryBuilder; 

public class MyBatisUtil  { 
  private  static SqlSessionFactory sqlSessionFactory; 
  static { 
     String resource = "resource/mybatis-config.xml"; 
     Reader reader = null; 
     try { 
         reader = Resources.getResourceAsReader(resource);
         sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
         reader.close();
     } catch (IOException e) {
         System.out.println(e.getMessage()); 
     } 
  } 
  
  public static SqlSessionFactory getSqlSessionFactory() { 
     return sqlSessionFactory; 
  } 
} 